<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="../../../static/js/vue.js"></script>
    <script src="../../../static/js/config.js"></script>
    <link rel="stylesheet" href="../../../static/layui/css/layui.css"></link>
    <script src="../../../static/js/jquery-3.3.1.min.js"></script>
</head>
<body>
<div id="app">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>用户登录</legend>
    </fieldset>
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户名:</label>
            <div class="layui-input-block">
                <input type="text" v-model="username" name="title" required lay-verify="required" placeholder="请输入用户名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码:</label>
            <div class="layui-input-block">
                <input type="password" v-model="password" name="title" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">验证码:</label>
            <div class="layui-input-block">
                <input type="text" v-model="code" @keyup.enter="login" name="title" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input">
                <img :src="codeUrl" @click="freshenCode"/>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" @click="login">login</button>
                <button type="button" class="layui-btn" @click="register">register</button>
            </div>
        </div>
    </form>
</div>
<script src="../../../static/layui/layui.js"></script>
<script>
    layui.use('form', function(){

    });
</script>
<script type="text/javascript">
    var vm = new Vue({
        el: '#app',
        data:{
            username: '',
            password: '',
            code: '',
            codeUrl: serviceConfig.codeUrl
        },
        methods:{
            login: function () {
                apiConfig.loginApi({username:this.username,password:this.password,code:this.code}).then(function (result) {
                    if(methodConfig.requestMethod(result)){
                        window.location.href = webConfig.booksHtml
                    }
                })
            },
            register: function () {
                window.location.href = webConfig.registerHtml
            },
            freshenCode: function () {
                this.codeUrl = serviceConfig.codeUrl + '?' + Date.now()
            }
        }
    })
</script>
</body>
</html>
